home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / WANDR330.ZIP / SRC / PASSWORD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-27  |  2.5 KB  |  92 lines

  1. #include "wand_head.h"
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4.  
  5. #define PASS "cleverlights"
  6.  
  7. long dictsize = 0L;
  8. FILE *dictfp;
  9.  
  10. void scrn_passwd(num, passwd)    /* reads password num into passwd */
  11. int num;
  12. char *passwd;
  13. {
  14.     long position;
  15.  
  16.     position = PASSWD;
  17.     while (position >= dictsize)
  18.     position -= dictsize;
  19.     fseek(dictfp,position,SEEK_SET);
  20.     while (fgetc(dictfp) != '\n' && !feof(dictfp));
  21.     /* read a word into passwd */
  22.     if (fscanf(dictfp,"%s\n",passwd) == EOF) {
  23.     rewind(dictfp);
  24.     fscanf(dictfp,"%s\n",passwd);
  25.     }
  26. }
  27.  
  28. main(argc, argv)
  29. int argc;
  30. char *argv[];
  31. {
  32.     int scr, position, mpw = 0;
  33.     char pass[20];
  34.     char pw[100];
  35.     struct stat *statbuf;
  36.  
  37.     if(argc < 2) {
  38.     printf("Usage: %s screen1 screen2 ...\n",argv[0]);
  39.     exit(-1);
  40.     }
  41.  
  42. /* bjr@watserv1.waterloo.edu, added the following to fix password searching.
  43.    To properly search the 'words' dictionary, the size of the file
  44.    is needed.  As a result, there are now five conditions (there were
  45.    originally two,) under which passwords will be disabled.
  46.     1. The program was run with flag -e (screen editor)
  47.     2. The file no_pws is present in the screens directory
  48.     3. A stat() call on the dictionary file fails
  49.     4. The dictionary file cannot be opened using fopen()
  50.     5. The dictionary is empty (0 bytes)
  51.    The variable no_passwords has been replaced by dictsize.  If
  52.    dictsize = 0, passwords are disabled. */
  53.  
  54.     if (!stat(DICTIONARY, statbuf))    /* if we can stat dictionary */
  55.     if ((dictfp = fopen(DICTIONARY, "r")) != NULL)    /* and open */
  56.         dictsize = statbuf->st_size;    /* save size */
  57.     if (!dictsize) {
  58.     printf("%s: Cannot access %s.\n",argv[0],DICTIONARY);
  59.     fclose(dictfp);
  60.     exit(-1);
  61.     }
  62.  
  63.     position = 0;
  64.     while (++position < argc) {
  65.     if (atoi(argv[position])<1) {
  66.         printf("Option not known: %s.\n",argv[position]);
  67.         continue;
  68.     }
  69.     scr = atoi(argv[position]);
  70.     if ((scr < 100) && (mpw == 0)) {
  71.         printf("You need clearance to see passwords below 100.\n");
  72.         printf("Enter master password:");
  73.         scanf("%s",pw);
  74.         if (strncmp(pw,PASS,strlen(PASS))) {
  75.         printf("Foo, charlatan!\n");
  76.         exit(-1);
  77.         }
  78.         mpw = 1;
  79.     }
  80.         scrn_passwd((scr-1),pass);
  81.     printf("Screen %d password is '%s'.\n",scr,pass);
  82.     }
  83. #ifdef TOS
  84.     if (!strcmp(argv[0], "")) {    /* probably run from the desktop */
  85.     char c;
  86.     printf("Press any key to end...");
  87.     fflush(stdout);
  88.     c = console_read_byte(stdin);
  89.     }
  90. #endif    /* TOS */
  91. }
  92.